package Phase2Tests;
import Phase2.*;


import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class HypeerWebSetupTests 
{
	private Node baseNode;

	@Before
	public void setUp() throws Exception 
	{
		baseNode = new Node();
	}
	
	
	@Test
	public void threeNodes() throws InterruptedException
	{		
		boolean rootAccess = false;
		System.out.println("\n\nHypeerWeb Insert Testing is now starting...\n");
		
		Node[] nodeList = {baseNode, new Node(), new Node()};
		baseNode.insert(nodeList[1]);
		baseNode.insert(nodeList[2]);
		
		System.out.println(baseNode);
		System.out.println(baseNode.getNeighbours(rootAccess).getMin());
		System.out.println(baseNode.getNeighbours(rootAccess).getMax() + "\n");
		
		CheckHyperWeb.threeNodes(nodeList);
		
	}
	
	@Test
	public void fourNodes() throws InterruptedException
	{
		boolean rootAccess = false;
		Node[] nodeList = {baseNode, new Node(), new Node(), new Node()};
		
		baseNode.insert(nodeList[1]);
		baseNode.insert(nodeList[2]);
		baseNode.insert(nodeList[3]);
		
		System.out.println(baseNode.toString());
		System.out.println(baseNode.getNeighbours(rootAccess).getMin());
		System.out.println(baseNode.getNeighbours(rootAccess).getMax());
		System.out.println(baseNode.getNeighbours(rootAccess).getMax().getNeighbours(rootAccess).getMax() + "\n");
		
		CheckHyperWeb.fourNodes(nodeList);
	}
	
	@Test
	public void fiveNodes() throws InterruptedException
	{
		boolean rootAccess = false;
		Node[] nodeList = {baseNode, new Node(), new Node(), new Node(), new Node()};
		
		baseNode.insert(nodeList[1]);
		//baseNode.insert(nodeList[2]);
		nodeList[1].insert(nodeList[2]);
		nodeList[1].insert(nodeList[3]);
		nodeList[2].insert(nodeList[4]);
		
		System.out.println(nodeList[0]);
		System.out.println(nodeList[1]);
		System.out.println(nodeList[2]);
		System.out.println(nodeList[3]);
		System.out.println(nodeList[4] + "\n");
		
		Node assertNode = nodeList[4];
		int[] up = {};
		int[] down = {1, 2};
		int[] neighbour = {0};
		Assert.assertArrayEquals(up, assertNode.getUpPointers(false).idToArray());
		Assert.assertArrayEquals(down, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour, assertNode.getNeighbours(rootAccess).idToArray());
		Assert.assertEquals(3, assertNode.getFold(rootAccess).getId(rootAccess));
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("DownState", assertNode.getState(rootAccess).toString());
	}
	
	@Test
	public void sixNodes() throws InterruptedException
	{
		boolean rootAccess = false;
		Node[] nodeList = {baseNode, new Node(), new Node(), new Node(), new Node(), new Node()};
		
		baseNode.insert(nodeList[1]);
		baseNode.insert(nodeList[2]);
		baseNode.insert(nodeList[3]);
		baseNode.insert(nodeList[4]);
		nodeList[3].insert(nodeList[5]);
		
		System.out.println(nodeList[0]);
		System.out.println(nodeList[1]);
		System.out.println(nodeList[2]);
		System.out.println(nodeList[3]);
		System.out.println(nodeList[4]);
		System.out.println(nodeList[5] + "\n");
		
		Node assertNode = nodeList[5];
		int[] up = {};
		int[] down = {3};
		int[] neighbour = {1, 4};
		Assert.assertArrayEquals(up, assertNode.getUpPointers(false).idToArray());
		Assert.assertArrayEquals(down, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour, assertNode.getNeighbours(rootAccess).idToArray());
		Assert.assertEquals(2, assertNode.getFold(rootAccess).getId(rootAccess));
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("DownState", assertNode.getState(rootAccess).toString());
	}
	
	@Test
	public void eightNodes() throws InterruptedException
	{
		boolean rootAccess = false;
		Node[] nodeList = {baseNode, new Node(), new Node(), new Node(), new Node(),
			new Node(), new Node(), new Node(), };
		
		baseNode.insert(nodeList[1]);
		baseNode.insert(nodeList[2]);
		baseNode.insert(nodeList[3]);
		baseNode.insert(nodeList[4]);
		baseNode.insert(nodeList[5]);
		baseNode.insert(nodeList[6]);
		baseNode.insert(nodeList[7]);
		
		System.out.println(nodeList[0]);
		System.out.println(nodeList[1]);
		System.out.println(nodeList[2]);
		System.out.println(nodeList[3]);
		System.out.println(nodeList[4]);
		System.out.println(nodeList[5]);
		System.out.println(nodeList[6]);
		System.out.println(nodeList[7] + "\n");
		
		Node assertNode = nodeList[6];
		int[] up = {};
		int[] down = {};
		int[] neighbour = {2, 4, 7};
		Assert.assertArrayEquals(up, assertNode.getUpPointers(false).idToArray());
		Assert.assertArrayEquals(down, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour, assertNode.getNeighbours(rootAccess).idToArray());
		Assert.assertEquals(1, assertNode.getFold(rootAccess).getId(rootAccess));
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("EmptyState", assertNode.getState(rootAccess).toString());
		
		assertNode = nodeList[7];
		int[] up1 = {};
		int[] down1 = {};
		int[] neighbour1 = {3, 5, 6};
		Assert.assertArrayEquals(up1, assertNode.getUpPointers(false).idToArray());
		Assert.assertArrayEquals(down1, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour1, assertNode.getNeighbours(rootAccess).idToArray());
		Assert.assertEquals(0, assertNode.getFold(rootAccess).getId(rootAccess));
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("LastState", assertNode.getState(rootAccess).toString());
		
	}
	
	@Test
	public void nineNodes() throws InterruptedException
	{
		Node[] nodeList = {baseNode, new Node(), new Node(), new Node(), new Node(),
			new Node(), new Node(), new Node(), new Node(), };
		
		baseNode.insert(nodeList[1]);
		baseNode.insert(nodeList[2]);
		baseNode.insert(nodeList[3]);
		baseNode.insert(nodeList[4]);
		baseNode.insert(nodeList[5]);
		baseNode.insert(nodeList[6]);
		baseNode.insert(nodeList[7]);
		baseNode.insert(nodeList[8]);
		
		System.out.println(nodeList[0]);
		System.out.println(nodeList[1]);
		System.out.println(nodeList[2]);
		System.out.println(nodeList[3]);
		System.out.println(nodeList[4]);
		System.out.println(nodeList[5]);
		System.out.println(nodeList[6]);
		System.out.println(nodeList[7]);
		System.out.println(nodeList[8] + "\n");
		/*
		Node assertNode = nodeList[6];
		int[] up = {};
		int[] down = {};
		int[] neighbour = {2, 4, 7};
		Assert.assertArrayEquals(up, assertNode.getUpPointers().idToArray());
		Assert.assertArrayEquals(down, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour, assertNode.getNeighbours().idToArray());
		Assert.assertEquals(1, assertNode.getFold().getId());
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("EmptyState", assertNode.getState().toString());
		
		assertNode = nodeList[7];
		int[] up1 = {};
		int[] down1 = {};
		int[] neighbour1 = {3, 5, 6};
		Assert.assertArrayEquals(up1, assertNode.getUpPointers().idToArray());
		Assert.assertArrayEquals(down1, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour1, assertNode.getNeighbours().idToArray());
		Assert.assertEquals(0, assertNode.getFold().getId());
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("LastState", assertNode.getState().toString());
		*/
	}
	
	@Test
	public void twelveNodes() throws InterruptedException
	{
		Node[] nodeList = {baseNode, new Node(), new Node(), new Node(), new Node(),
			new Node(), new Node(), new Node(), new Node(), new Node(), new Node(), new Node(), };
		
		baseNode.insert(nodeList[1]);
		baseNode.insert(nodeList[2]);
		baseNode.insert(nodeList[3]);
		baseNode.insert(nodeList[4]);
		baseNode.insert(nodeList[5]);
		baseNode.insert(nodeList[6]);
		baseNode.insert(nodeList[7]);
		baseNode.insert(nodeList[8]);
		baseNode.insert(nodeList[9]);
		baseNode.insert(nodeList[10]);
		baseNode.insert(nodeList[11]);
		
		System.out.println(nodeList[0]);
		System.out.println(nodeList[1]);
		System.out.println(nodeList[2]);
		System.out.println(nodeList[3]);
		System.out.println(nodeList[4]);
		System.out.println(nodeList[5]);
		System.out.println(nodeList[6]);
		System.out.println(nodeList[7]);
		System.out.println(nodeList[8]);
		System.out.println(nodeList[9]);
		System.out.println(nodeList[10]);
		System.out.println(nodeList[11] + "\n");
		/*
		Node assertNode = nodeList[6];
		int[] up = {};
		int[] down = {};
		int[] neighbour = {2, 4, 7};
		Assert.assertArrayEquals(up, assertNode.getUpPointers().idToArray());
		Assert.assertArrayEquals(down, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour, assertNode.getNeighbours().idToArray());
		Assert.assertEquals(1, assertNode.getFold().getId());
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("EmptyState", assertNode.getState().toString());
		
		assertNode = nodeList[7];
		int[] up1 = {};
		int[] down1 = {};
		int[] neighbour1 = {3, 5, 6};
		Assert.assertArrayEquals(up1, assertNode.getUpPointers().idToArray());
		Assert.assertArrayEquals(down1, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour1, assertNode.getNeighbours().idToArray());
		Assert.assertEquals(0, assertNode.getFold().getId());
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("LastState", assertNode.getState().toString());
		*/
	}
	
	@Test
	public void fifteenNodes() throws InterruptedException
	{
		Node[] nodeList = {baseNode, new Node(), new Node(), new Node(), new Node(),
			new Node(), new Node(), new Node(), new Node(), new Node(),
			new Node(), new Node(), new Node(), new Node(), new Node(), };
		
		baseNode.insert(nodeList[1]);
		baseNode.insert(nodeList[2]);
		baseNode.insert(nodeList[3]);
		baseNode.insert(nodeList[4]);
		baseNode.insert(nodeList[5]);
		baseNode.insert(nodeList[6]);
		baseNode.insert(nodeList[7]);
		baseNode.insert(nodeList[8]);
		baseNode.insert(nodeList[9]);
		baseNode.insert(nodeList[10]);
		baseNode.insert(nodeList[11]);
		baseNode.insert(nodeList[12]);
		baseNode.insert(nodeList[13]);
		baseNode.insert(nodeList[14]);
		
		System.out.println(nodeList[0]);
		System.out.println(nodeList[1]);
		System.out.println(nodeList[2]);
		System.out.println(nodeList[3]);
		System.out.println(nodeList[4]);
		System.out.println(nodeList[5]);
		System.out.println(nodeList[6]);
		System.out.println(nodeList[7]);
		System.out.println(nodeList[8]);
		System.out.println(nodeList[9]);
		System.out.println(nodeList[10]);
		System.out.println(nodeList[11]);
		System.out.println(nodeList[12]);
		System.out.println(nodeList[13]);
		System.out.println(nodeList[14] + "\n");
		/*
		Node assertNode = nodeList[6];
		int[] up = {};
		int[] down = {};
		int[] neighbour = {2, 4, 7};
		Assert.assertArrayEquals(up, assertNode.getUpPointers().idToArray());
		Assert.assertArrayEquals(down, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour, assertNode.getNeighbours().idToArray());
		Assert.assertEquals(1, assertNode.getFold().getId());
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("EmptyState", assertNode.getState().toString());
		
		assertNode = nodeList[7];
		int[] up1 = {};
		int[] down1 = {};
		int[] neighbour1 = {3, 5, 6};
		Assert.assertArrayEquals(up1, assertNode.getUpPointers().idToArray());
		Assert.assertArrayEquals(down1, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour1, assertNode.getNeighbours().idToArray());
		Assert.assertEquals(0, assertNode.getFold().getId());
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("LastState", assertNode.getState().toString());
		*/
	}
	
	@Test
	public void sixteenNodes() throws InterruptedException
	{
		Node[] nodeList = {baseNode, new Node(), new Node(), new Node(), new Node(),
			new Node(), new Node(), new Node(), new Node(), new Node(),
			new Node(), new Node(), new Node(), new Node(), new Node(),
			new Node(), };
		
		baseNode.insert(nodeList[1]);
		baseNode.insert(nodeList[2]);
		baseNode.insert(nodeList[3]);
		baseNode.insert(nodeList[4]);
		baseNode.insert(nodeList[5]);
		baseNode.insert(nodeList[6]);
		baseNode.insert(nodeList[7]);
		baseNode.insert(nodeList[8]);
		baseNode.insert(nodeList[9]);
		baseNode.insert(nodeList[10]);
		baseNode.insert(nodeList[11]);
		baseNode.insert(nodeList[12]);
		baseNode.insert(nodeList[13]);
		baseNode.insert(nodeList[14]);
		baseNode.insert(nodeList[15]);
		
		System.out.println(nodeList[0]);
		System.out.println(nodeList[1]);
		System.out.println(nodeList[2]);
		System.out.println(nodeList[3]);
		System.out.println(nodeList[4]);
		System.out.println(nodeList[5]);
		System.out.println(nodeList[6]);
		System.out.println(nodeList[7]);
		System.out.println(nodeList[8]);
		System.out.println(nodeList[9]);
		System.out.println(nodeList[10]);
		System.out.println(nodeList[11]);
		System.out.println(nodeList[12]);
		System.out.println(nodeList[13]);
		System.out.println(nodeList[14]);
		System.out.println(nodeList[15] + "\n");
		/*
		Node assertNode = nodeList[6];
		int[] up = {};
		int[] down = {};
		int[] neighbour = {2, 4, 7};
		Assert.assertArrayEquals(up, assertNode.getUpPointers().idToArray());
		Assert.assertArrayEquals(down, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour, assertNode.getNeighbours().idToArray());
		Assert.assertEquals(1, assertNode.getFold().getId());
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("EmptyState", assertNode.getState().toString());
		
		assertNode = nodeList[7];
		int[] up1 = {};
		int[] down1 = {};
		int[] neighbour1 = {3, 5, 6};
		Assert.assertArrayEquals(up1, assertNode.getUpPointers().idToArray());
		Assert.assertArrayEquals(down1, assertNode.getDownPointers(false).idToArray());
		Assert.assertArrayEquals(neighbour1, assertNode.getNeighbours().idToArray());
		Assert.assertEquals(0, assertNode.getFold().getId());
		Assert.assertEquals(null, assertNode.getOldFold());
		Assert.assertEquals("LastState", assertNode.getState().toString());
		*/
	}
	
	@Test
	public void oneThousandNodesAdded() throws InterruptedException
	{
		for (int i = 0; i < 1000; i++)
		{
			baseNode.insert(new Node());
		}
		
		System.out.println("1000 Nodes added to a HypeerWeb.");

		System.out.println(baseNode.printAllNode());
	}

	@After
	public void tearDown() throws Exception 
	{
		
	}

}
